package com.jackchong.utils;


import android.util.Log;

import com.jackchong.base.BaseApplication;
import com.orhanobut.logger.Logger;

import java.util.ArrayList;
import java.util.List;

/**
 * 作者: jack(黄冲)
 * 邮箱: 907755845@qq.com
 * create on 2018/11/20 10:19
 */

public class JLog {


    private static final String TAG = "jlog";


    private static String createMessage(String msg) {
        String functionName = getFunctionName();
        return  (functionName == null ? msg : (functionName + "\n" + msg));
    }


    private static String getFunctionName() {
        StackTraceElement[] sts = Thread.currentThread().getStackTrace();

        for (StackTraceElement st : sts) {
            if (st.isNativeMethod()) {
                continue;
            }

            if (st.getClassName().equals(Thread.class.getName())) {
                continue;
            }

            if (st.getClassName().equals(JLog.class.getName())) {
                continue;
            }

            return TimeUtils.getDate(TimeUtils.DATE_FORMAT_2, System.currentTimeMillis()) + "  "+st.getFileName() + "." + st.getMethodName() + ":" + st.getLineNumber();
        }

        return null;
    }


    private static String getString(Object... message){
        StringBuilder buffer = new StringBuilder();
        for (Object o : message) {
            buffer.append(o);
            buffer.append("    ");
        }
        return buffer.toString();
    }

    public static void v(String tag, Object... message) {
        if (!BaseApplication.RELEASE_MODE) {
            Log.v(TAG + "-" + tag, getString(message));
        }
    }


    public static void i(String tag, String message) {
        if (!BaseApplication.RELEASE_MODE) {
            if (tag.contains("http")) {
                Log.i(TAG + "-" + tag, getString(message));
            }else  {
                Logger.t(tag).i(message);
            }
        }
    }

    public static void i(String tag, Object... message) {
        if (!BaseApplication.RELEASE_MODE) {
            Logger.t(tag).i(getString(message));
        }
    }


    public static void w(String tag, Object... message) {
        if (!BaseApplication.RELEASE_MODE) {
            Logger.t(tag).w(getString(message));
        }
    }


    public static void e(String tag, Object... message) {
        if (!BaseApplication.RELEASE_MODE) {
            Logger.t(tag).e(getString(message));
        }
    }

    public static void e(String message) {
        if (!BaseApplication.RELEASE_MODE) {
            Logger.e(message);
        }
    }
    public static void d(Object... message) {
        if (!BaseApplication.RELEASE_MODE) {
            Logger.d(getString(message));
        }
    }

    public static void d(String tag, Object... message) {
        if (!BaseApplication.RELEASE_MODE) {
            Log.d(TAG + "-" + tag, getString(message));
        }
    }

    public static void json(String json) {
        if (!BaseApplication.RELEASE_MODE) {
            Logger.json(json);
        }
    }

    public static void json(String tag, String json) {
        if (!BaseApplication.RELEASE_MODE) {
            Log.d(TAG + "-" + tag, json);
            Log.d(TAG + "-" + tag, "┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄");
        }
    }
}
